package com.bdth.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * Created by Administrator on 2017/4/25.
 */
public class DTUtils
{
    /**
     * 技术两个时间的相差天数
     * @param start 开始时间
     * @param end 结束时间
     * @return 相差天数
     */
    public static int differentDaysByMillisecond(String start, String end)
    {
        Date d1 = null, d2 = null;
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        try
        {
            d1 = format.parse(start);
            d2 = format.parse(end);
        }
        catch (ParseException e)
        {
            e.printStackTrace();
        }
        
        int days = (int) ((d2.getTime() - d1.getTime()) / (1000 * 3600 * 24));
        return days;
    }
    
    public static void main(String[] args)
    {
        String start = "2017-06-02 10:23:00";
        String now = getFormatTime();
        //System.out.println(DTUtils.differentDaysByMillisecond(start, now));
    }
    
    public static String getFormatTime()
    {
        Date date = new Date();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        return sdf.format(date);
    }
}
